package ae.pcfc.etks.online.itworx.ehs.web.compensation;

import ae.pcfc.etks.online.itworx.ehs.web.delegate.IMSDelegate;
import ae.pcfc.etks.online.itworx.ehs.web.enums.IMSRequestStatus;
import ae.pcfc.etks.online.itworx.ehs.web.util.UtilCommon;

public class IMSCompensationManager implements CompensationManager {

	IMSDelegate imsDelegate;

	public void setImsDelegate(IMSDelegate imsDelegate) {
		this.imsDelegate = imsDelegate;
	}

	@Override
	public boolean rollback(Object rollbackKey) throws Exception{
		if(rollbackKey != null){
			String imsLogId = (String) rollbackKey; 
			if(!UtilCommon.isEmpty(imsLogId)){
				IMSRequestStatus status = imsDelegate.retrieveIMSStatus(imsLogId);
				if(status != null){
					if(!IMSRequestStatus.CLOSED.equals(status)){
						imsDelegate.cancelIMPSRecord(imsLogId);
					}
				}
				return true;
			}
		}
		return false;
	}

}
